package com.shujia.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class HiveJDBCDemo1 {
    public static void main(String[] args) throws Exception {
        //加载驱动
        Class.forName("org.apache.hive.jdbc.HiveDriver");
        //创建Hive连接对象
        Connection conn = DriverManager.getConnection("jdbc:hive2://master:10000/bigdata27");
        //获取Hivesql操作对象
        Statement state = conn.createStatement();
        ResultSet resultSet = state.executeQuery("select * from students");
        while (resultSet.next()) {
            String id = resultSet.getString(1);
            String name = resultSet.getString(2);
            String age = resultSet.getString(3);
            String gender = resultSet.getString(4);
            String clazz = resultSet.getString(5);
            System.out.println(id + "," + name + "," + age + "," + gender + "," + clazz);
        }

        //释放资源
        resultSet.close();
        state.close();
        conn.close();

    }
}
